package hbase.template;

import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * Created by dave on 18-7-21 下午11:10.
 */
public class CellMapper {

    public static String toString(Result result, String family, String column) {
        return Bytes.toString(toBytes(result, family, column));
    }

    public static int toInt(Result result, String family, String column) {
        return Bytes.toInt(toBytes(result, family, column));
    }

    public static short toShort(Result result, String family, String column) {
        return Bytes.toShort(toBytes(result, family, column));
    }

    public static long toLong(Result result, String family, String column) {
        return Bytes.toLong(toBytes(result, family, column));
    }

    public static boolean toBoolean(Result result, String family, String column) {
        return Bytes.toBoolean(toBytes(result, family, column));
    }

    public static float toFloat(Result result, String family, String column) {
        return Bytes.toFloat(toBytes(result, family, column));
    }

    public static double toDouble(Result result, String family, String column) {
        return Bytes.toDouble(toBytes(result, family, column));
    }

    public static byte[] toBytes(Result result, String family, String column) {
        return CellUtil.cloneValue(result.getColumnLatestCell(family.getBytes(), column.getBytes()));
    }
}
